package com.taotao.portal.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.taotao.common.pojo.TaotaoResult;
import com.taotao.common.utils.HttpClientUtil;
import com.taotao.common.utils.JsonUtils;
import com.taotao.pojo.TbContent;
import com.taotao.portal.pojo.AdItem;
import com.taotao.portal.service.AdService;

@Service
public class AdServiceImpl implements AdService {

	
	@Value("${REST_BASE_URL}")
	private String REST_BASE_URL;
	@Value("${INDEX_AD1_URL}")
	private String INDEX_AD1_URL;

	
	@Override
	public List<AdItem> getAdItemList() {
		String jsonData = HttpClientUtil.doGet(REST_BASE_URL+INDEX_AD1_URL+"/"+89);
		
		TaotaoResult result = JsonUtils.jsonToPojo(jsonData, TaotaoResult.class);
		
		List<AdItem> list=new ArrayList<AdItem>();
		if(result.getStatus()==200) {
			String data=(String) result.getData();
			List<TbContent> contentList=JsonUtils.jsonToList(data, TbContent.class);
			for(TbContent content : contentList) {
				AdItem item = new AdItem();
				item.setHeight(240);
				item.setWidth(670);
				item.setSrc(content.getPic());
				item.setHeightB(240);
				item.setWidth(550);
				item.setSrcB(content.getPic2());
				item.setAlt(content.getTitleDesc());
				item.setHref(content.getUrl());
				list.add(item);

			}
			
		}
		return list;
	}

}
